﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ISHotel.Database;

namespace ISHotel.presentation
{
    public partial class TaxaForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ButtonVlozTaxy_Click(object sender, EventArgs e)
        {
            Taxa newTaxa = new Taxa();
            newTaxa.nazev_taxy = TextBoxNazev.Text;
            newTaxa.popis_taxy = TextBoxPopis.Text;
            newTaxa.cena_taxy = Convert.ToInt32(TextBoxCena.Text);

            TaxaTable addSourceRecord = new TaxaTable();
            addSourceRecord.Insert(newTaxa);

            Response.Redirect(Request.RawUrl);
        }

        public void button_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "DeleteTaxa")
            {
                TaxaTable delSourceRecord = new TaxaTable();
                
                try
                {
                    delSourceRecord.Delete(Convert.ToInt32(e.CommandArgument));
                }
                catch (Exception ex)
                {
                    LabelErr.Text = "Taxa nelze smazat, je již použita v objednávce.";
                }

                

                if (LabelErr.Text == "")
                {
                    Response.Redirect(Request.RawUrl);
                }
            }
        }

        protected void TaxaDetail_OnUpdated(object sender, EventArgs e)
        {
            GridViewTaxa.DataBind();
            DetailsView1.DataBind();
        }
    }
}